package vip.meeet.concurrent;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

public class VolatilePP {
    
    static volatile int num;
    
    static AtomicInteger ai = new AtomicInteger(1);
    static CountDownLatch latch = new CountDownLatch(5);
    public static void main(String[] args) {
        ExecutorService pool = Executors.newFixedThreadPool(5);
        for(int i=0;i<5;i++){
            PP pp = new PP();
            pool.submit(pp);
        }
        try {
            latch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        pool.shutdownNow();
        System.out.println(num);
        System.out.println(ai.getAndIncrement());
    }
    
    static class PP implements Runnable{

        @Override
        public void run() {
            int i = 10000;
            do{
//              ++num;
                ai.getAndIncrement();
            }while(--i > 0);
            latch.countDown();
        }
        
    }

}
